package eshin.blog.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import eshin.blog.beans.Article;
import eshin.blog.dao.ArticleDAO;
import eshin.blog.dao.CritiqueDAO;
import eshin.blog.service.ArticleService;
import eshin.blog.utils.Page;
import eshin.blog.utils.PageUtil;
import eshin.blog.utils.Result;
@Transactional
@Service("articleService")
public class ArticleServiceImpl implements ArticleService {
	@Resource private ArticleDAO articleDAO;
	@Resource private CritiqueDAO critiqueDAO;


	public void addArticle(Article article) {
		articleDAO.add(article);
	}


	public List<Article> showUserAllArticle(String username) {
		return articleDAO.queryUserAll(username);
	}


	public Result showUserArticleByPage(String username, Page page) {
		page = PageUtil.createPage(page,articleDAO.queryUserAllCount(username));
		List<Article> all = articleDAO.queryByPage(username, page);
		Result result = new Result();
		result.setPage(page);
		result.setList(all);
		return result;
	}


	public Result showArticleByPage(Page page) {
		page = PageUtil.createPage(page,articleDAO.queryAllCount());
		List<Article> all = articleDAO.queryAllByPage(page);
		Result result = new Result();
		result.setPage(page);
		result.setList(all);
		return result;
	}


	public Article showArticle(int id) {
		return articleDAO.queryById(id);
	}


	public int getCritiqueCount(int AId) {
		return critiqueDAO.queryCritiqueCount(AId);
	}

}
